Direct shebang execution#116
Conversation
d6f2d70 to
d66a9b7
Compare
|
Avoid unnecessary capitalization. i.e., "Direct Shebang Execution" -> "Direct shebang execution" |
| if (nread < 2 || buf[0] != '#' || buf[1] != '!') { | ||
| return 0; /* Not a shebang script */ | ||
| } |
There was a problem hiding this comment.
It is confusing to have shebang detection in function elf_parse_shebang. Clarify it.
There was a problem hiding this comment.
That is a fair point. The function is responsible for both detection (checking for the #! signature) and parsing. Combining them into a single function avoids having to open, read, and close the file twice (once for detection and once for parsing).
To clarify this dual responsibility, I have:
- Updated the doc comment in elf.h and the function header in elf.c to explicitly state that
elf_parse_shebangperforms both detection (returning0if not a shebang script) and parsing.- Kept the callers in
main.candexec.csimple by delegating both checks entirely to this function."
23ed4fa to
430f0e4
Compare
jserv
left a comment
There was a problem hiding this comment.
Shebang refactor is a clear improvement. One correctness issue worth addressing (nested shebang via execve), plus the naming clarification raised in the earlier thread. Lower-value notes: the argv buf_off in exec.c recovers its offset via pointer subtraction from argv[argc-1] -- brittle, better returned from read_string_array; and the CR/early-EOL dialect is worth a one-line contract note plus tests (CRLF, blank interp, no trailing newline).
| if (fd < 0) | ||
| return -errno; | ||
|
|
||
| char buf[512]; |
There was a problem hiding this comment.
Low: reads 511 of 512 bytes then treats the first line as complete; an over-long interpreter path is silently truncated rather than rejected. str_copy_trunc's size check catches the common case. Consider rejecting an unterminated first line. (Still more generous than Linux BINPRM_BUF_SIZE=256.)
|
When writing Git commit messages, avoid formatting them like this: At first glance, this reads more like a haiku than a commit message. Since Git conventionally allows up to 72 characters per line in the message body, wrap the text naturally while making good use of the available width. For example: The goal is not to make every line exactly 72 characters long, but to avoid unnecessarily short lines. Wrap at sensible boundaries so that the text remains easy to read while making efficient use of the available line width. |
430f0e4 to
e65ed30
Compare
|
I have implemented all the requested updates from the new code review comments:
All changes compile cleanly and pass the native unit tests. |
We are humans. Don't copy agent-specific reply here. |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
Do you have any tool to help format the git commit message? |
Implemented a recursive shebang parsing loop in the standalone loader's entry point. It reads shebang interpreter lines, including optional arguments like #!/bin/sh -x, updates elf_path to the interpreter, and prepends them to guest_argv while resolving the host path recursively up to a maximum recursion depth of five interpreter levels.
e65ed30 to
10b9d69
Compare
|
Thank @doanbaotrung for contributing! |
Refactor shebang parsing logic: Extract the duplicate binfmt_script parsing logic from main.c and exec.c into a shared helper function elf_parse_shebang defined in elf.c and declared in elf.h.
Summary by cubic
Enables direct execution of shebang scripts by resolving interpreters in the standalone loader and execve with bounded recursion (max 5) and consistent errno handling. Adds a shared shebang parser and a host unit test for edge cases.
New Features
Refactors
Written for commit 10b9d69. Summary will update on new commits.